package com.hbfu.zggdwlzzsx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hbfu.zggdwlzzsx.entity.Categories;
import com.hbfu.zggdwlzzsx.entity.Works;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WorkMapper extends BaseMapper<Works> {

    //根据id多表查询某个数据
    @Select("select * from works where id=#{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "id",property = "chapters", javaType = List.class,
                    many = @Many(select = "com.hbfu.zggdwlzzsx.mapper.ChapterMapper.getChapteriesByWorkId")),
            @Result(column = "work_picture",property = "workPicture"),
            @Result(column = "name",property = "name"),
            @Result(column = "author_name",property = "authorName"),
            @Result(column = "synopsis",property = "synopsis")
    })
    public Works getWorkById(Integer id);

    @Select("select * from works where author_name=#{name}")
    public List<Works> getWorkByAuthorName(String name);


    /*@Select("select * from works where name LIKE CONCAT('%', #{name}, '%')")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "id",property = "Categories", javaType = List.class,
                    many = @Many(select = "com.hbfu.zggdwlzzsx.mapper.CategoryMapper.selectList")),
            @Result(column = "work_picture",property = "workPicture"),
            @Result(column = "name",property = "name"),
            @Result(column = "author_name",property = "authorName"),
            @Result(column = "synopsis",property = "synopsis")
    })
    List<Works> getworks(String name, Integer categoryId);*/


}
